using IQIGame.Onigao.GamePlay;

namespace IQIGame.Onigao.Logic
{
    /// <summary>
    /// 将关卡参数进行关联运算
    /// 参数组1：1：模式(1:设置 2:增加 3.减少)，2：可写参数ID，3：可读参数ID
    /// </summary>
    public class ExecRelationalCalcLevelParams : BaseServiceExecution
    {
        public override void Execute(LevelRegion region, LevelPlayer player)
        {
            var config = _config as ExecParamRelationalCalcLevelParams;

            int intType = config.type;
            if (intType != 1 && intType != 2 && intType != 3)
            {
                PrintParamInvalidError();
                intType = 1;
            }
            ExecValueOperationType type = (ExecValueOperationType)intType;
            int writeParamId = config.writeParamId;
            int readParamId = config.readParamId;
            int originalValue = region.level.GetLevelParam(writeParamId);
            int refValue = region.level.GetLevelParam(readParamId);
            int value = 0;
            switch (type)
            {
                case ExecValueOperationType.Set:
                    value = refValue;
                    break;
                case ExecValueOperationType.Add:
                    value = originalValue + refValue;
                    break;
                case ExecValueOperationType.Reduce:
                    value = originalValue - refValue;
                    break;
                default:
                    break;
            }
            region.level.SetLevelParam(writeParamId, value, ExecChangeValueType.Full);
        }
    }
}
